<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="编号" prop="number">
        <el-input  v-model="form.numberNum" disabled style="width: 280px;"/>
      </el-form-item>
      <el-form-item label="合同名称" prop="contactName">
        <el-input v-model="form.contactName" :disabled='isdisabled' style="width: 280px;" placeholder="请输入合同名称" />
      </el-form-item>
      <el-form-item label="合同编号" prop="contactNum">
        <el-input v-model="form.contactNum" :disabled='isdisabled' style="width: 280px;" placeholder="请输入合同编号" />
      </el-form-item>
      <el-form-item label="签约日期" prop="signDate">
        <el-date-picker clearable
                        style="width: 280px;"
                        v-model="form.signDate"
                        type="date"
                        format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd"
                        :disabled='isdisabled'
                        placeholder="请选择签约日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="我方单位名称" prop="ourUnitName">
        <el-input style="width: 280px;" v-model="form.ourUnitName" :disabled='isdisabled' placeholder="请输入我方单位名称" />
      </el-form-item>
      <el-form-item label="我方负责人" prop="ourHeader">
        <el-input style="width: 280px;" v-model="form.ourHeader" :disabled='isdisabled' placeholder="请输入我方负责人" />
      </el-form-item>
      <el-form-item label="对方单位名称" prop="otherUnitName">
        <el-input style="width: 280px;" v-model="form.otherUnitName" :disabled='isdisabled' placeholder="请输入对方单位名称" />
      </el-form-item>
      <el-form-item label="对方负责人" prop="otherHeader">
        <el-input style="width: 280px;" v-model="form.otherHeader" :disabled='isdisabled' placeholder="请输入对方负责人" />
      </el-form-item>
      <el-form-item label="附件">
        <file-upload v-model="form.attachment" :isDisabled="isdisabled"/>
      </el-form-item>
    </el-form>
      <div v-show="parentTaskId==null" class="dialog-footer" style="text-align:center">
          <el-button :loading="buttonLoading" size="small" type="info" @click="submitCallback">关闭</el-button>
          <el-button :loading="buttonLoading" size="small" type="primary" @click="submitForm" v-if="confirmVisible">提交</el-button>
      </div>
      <!-- 工作流开始 -->
      <verify ref="verifyRef" :taskId="taskId" @submitCallback="submitCallback"
              :componentName="componentName"
              :taskVariables="taskVariables" :sendMessage="sendMessage"></verify>
  </div>
</template>

<script>
import { getAdministrateContact } from "@/api/oa/administrateContact";
import verify from "@/components/Process/Verify";
import {parseTime} from "@/utils/ruoyi";
export default {
  name: "AdministrateContactForm",
  components: {
      verify
  },
  props: {
      businessKey: String, // 业务唯一标识
      parentTaskId: String, // 父级任务id
      taskId: String, // 任务id
      confirmVisible:{
          type: Boolean,
          default: true
      }
  },
  data() {
    return {
      componentName:"合同审批申请",
      isdisabled:true,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 表单参数
      form: {},
        projectNameList:[],
      // 表单校验
      rules: {
        contactName: [
          { required: true, message: "合同名称不能为空", trigger: "blur" }
        ],
        contactNum: [
          { required: true, message: "合同编号不能为空", trigger: "blur" }
        ],
        signDate: [
          { required: true, message: "签约日期不能为空", trigger: "blur" }
        ],
      },
        taskVariables: undefined,
        //消息提醒
        sendMessage: {},
        processKey: "oa_administrate_cont",
    };
  },
  watch: {
      businessKey: {
          immediate: true, // 很重要！！！
          handler (newVal) {
              if(newVal) {
                  this.getById()
              }
          }
      }
  },
  methods: {
    submitCallback(){
        this.$emit("closeForm")
    },
    async getById() {
      const {data} = await getAdministrateContact(this.businessKey)
      this.form = data;
      if (data.actBusinessStatus.createTime){
            this.form.numberNum=this.processKey + '@' + parseTime(data.actBusinessStatus.createTime, '{y}{m}{d}{h}{i}{s}')
        }
    },
    /** 提交按钮 */
    submitForm() {
        getAdministrateContact(this.businessKey).then(response => {
            this.taskVariables = {
                entity: response.data,
            };
          this.sendMessage = {
            title: "合同审批提醒",
            messageContent: this.$store.state.user.nickName + "审批通过了合同审批"
          };
        });
        this.$refs.verifyRef.visible = true
        this.$refs.verifyRef.reset()
    },
  }
};
</script>
<style scoped>
    /* 设置滚动条宽度和高度 */
    ::v-deep .el-table__body-wrapper::-webkit-scrollbar {
        width: 8px; /* 横向滚动条 */
        height: 8px; /* 纵向滚动条 必写 */
    }
    /* 设置滚动条样式 */
    ::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
        background-color: #dde;
        border-radius: 3px;
    }
    #selectForm >>> .el-form-item__label {
        font-size: 12px;
    }
    ::v-deep .bjsm .el-form-item__content{
        width: calc(100% - 130px) !important;
    }
</style>
